home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra / disp186b.zip / IBM8514A.C < prev    next >
Text File  |  1994-02-23  |  6KB  |  228 lines

  1. /*
  2.  *  ibm8514a.c - Shell to initialize the 8514/A
  3.  *         Written by Jake Richter
  4.  *         Copyright (c) 1989,1990  Panacea Inc., Londonderry, NH
  5.  *
  6.  *         This program may be freely distributed and modified.
  7.  */
  8.  
  9. #include <dos.h>
  10. #include "reg8514a.h"
  11.  
  12. int status_8514A = (-1);    /* -1: not present, 0: VGA, 1: enabled */
  13.  
  14. /*
  15.  * check_8514A()
  16.  * =============
  17.  *  Check to see if an 8514/A is actually installed by
  18.  *  writing to the ERR_TERM register, and reading back. The
  19.  *  0x5A5A value is entirely arbitrary.
  20.  */
  21. int check_8514A(void)
  22. {
  23.     int status;
  24.  
  25.     outpw(ERR_TERM,0x5A5A);
  26.     if(inpw(ERR_TERM) != 0x5A5A) return(0);
  27.     outpw(ADVFUNC_CNTL,6);        /* make sure we are in VGA mode */
  28.     /*
  29.      * Reset the 8514/A, and disable all interrupts.
  30.      */
  31.     outpw(SUBSYS_CNTL,GPCTRL_RESET | CHPTEST_NORMAL);
  32.     outpw(SUBSYS_CNTL,GPCTRL_ENAB  | CHPTEST_NORMAL);
  33.     /*
  34.      * Get board status information.
  35.      */
  36.     status = inpw(SUBSYS_STAT);
  37.     /*
  38.      * Check if we can do 1024x768 with 256 colors.
  39.      * If not, don't bother with 8514A modes.
  40.      */
  41.     if((status & MONITORID_MASK) != MONITORID_8514) return(0);
  42.     if((status & _8PLANE) == 0) return(0);
  43.     /*
  44.      * OK, it's present and the modes we want are available
  45.      */
  46.     status_8514A = 0;
  47.     return(1);
  48. }
  49.  
  50. /*
  51.  * disable_8514A()
  52.  * ===============
  53.  *
  54.  *  go back to VGA mode
  55.  */
  56. void disable_8514A(void)
  57. {
  58.     if(status_8514A > 0) {
  59.         outpw(ADVFUNC_CNTL,6);    /* Return to VGA Mode */
  60.         status_8514A = 0;
  61.     }
  62. }
  63.  
  64. /*
  65.  * InitLUT()
  66.  * =========
  67.  *  Loads the Look-up Table with ramps of red, green, blue, and gray.
  68.  *  Assumes 8-bit board is in use. If 4 bit board, then only the first
  69.  *  16 entries in LUT will be used. Could be written more compact, but
  70.  *  has been expanded for greater readability.
  71.  */
  72. LUTENTRY lutData[16] = {    /* approximate default VGA colors */
  73.     0x00, 0x00, 0x00,        /* Black              */
  74.     0x00, 0x00, 0x7f,        /* Dark Blue              */
  75.     0x00, 0x7f, 0x00,        /* Dark Green              */
  76.     0x00, 0x7f, 0x7f,        /* Dark Cyan              */
  77.     0x7f, 0x00, 0x00,        /* Dark Red              */
  78.     0x7f, 0x00, 0x7f,        /* Dark Magenta              */
  79.     0x7f, 0x7f, 0x00,        /* Dark Yellow (Brown)          */
  80.     0x7f, 0x7f, 0x7f,        /* Gray                  */
  81.     0x1f, 0x1f, 0x1f,        /* Dark Gray (Almost Black)      */
  82.     0x00, 0x00, 0xff,        /* Bright Blue              */
  83.     0x00, 0xff, 0x00,        /* Bright Green              */
  84.     0x00, 0xff, 0xff,        /* Bright Cyan              */
  85.     0xff, 0x00, 0x00,        /* Bright Red              */
  86.     0xff, 0x00, 0xff,        /* Bright Magenta          */
  87.     0xff, 0xff, 0x00,        /* Bright Yellow          */
  88.     0xff, 0xff, 0xff        /* White              */
  89. };
  90.  
  91. static void InitLUT(void)
  92. {
  93.     int ii,jj;
  94.  
  95.     /*
  96.      * Start by setting the DAC Write Index to 0.
  97.      */
  98.     outp(DAC_W_INDEX,0);
  99.     /*
  100.      * Load all 256 LUT entries (pattern repeats after every 16 colors)
  101.      */
  102.     for(ii = 0; ii < 16; ii++) {
  103.         for(jj = 0; jj < 16; jj++) {
  104.         outp(DAC_DATA,lutData[jj].r >> 2);
  105.         outp(DAC_DATA,lutData[jj].g >> 2);
  106.         outp(DAC_DATA,lutData[jj].b >> 2);
  107.         }
  108.     }
  109. }
  110.  
  111. /*
  112.  * InitEnvironment()
  113.  * =================
  114.  *
  115.  *  Initializes the 8514/A's drawing environment and clears the display.
  116.  */
  117. void InitEnvironment(void)
  118. {
  119.     /*
  120.      * Current mixes, replace, foreground active
  121.      */
  122.     outpw(FRGD_MIX,FSS_FRGDCOL | MIX_REPLACE);
  123.     outpw(BKGD_MIX,BSS_BKGDCOL | MIX_REPLACE);
  124.     /*
  125.      * Clipping rectangle to full drawable space (0,0 to 1023, 1023).
  126.      */
  127.     outpw(MULTIFUNC_CNTL,SCISSORS_T | 0x000);
  128.     outpw(MULTIFUNC_CNTL,SCISSORS_L | 0x000);
  129.     outpw(MULTIFUNC_CNTL,SCISSORS_B | 0x3FF);
  130.     outpw(MULTIFUNC_CNTL,SCISSORS_R | 0x3FF);
  131.     /*
  132.      * Enable writes to all planes and reset color compare
  133.      */
  134.     outpw(WRT_MASK,0xFFFF);
  135.     outpw(MULTIFUNC_CNTL,PIX_CNTL | 0x0000);      /* Clear lower bits */
  136.     /*
  137.      * Clear the display. Need to set the color, origin, and size.
  138.      * Then draw. See Listing 7-5 for more information.
  139.      */
  140.     WaitQueue(6);
  141.     outpw(FRGD_COLOR,0);
  142.     outpw(CUR_X,0);
  143.     outpw(CUR_Y,0);
  144.     outpw(MAJ_AXIS_PCNT,1023);
  145.     outpw(MULTIFUNC_CNTL,MIN_AXIS_PCNT | 1023);
  146.     outpw(CMD,CMD_RECT | INC_Y | INC_X | DRAW | PLANAR | WRTDATA);
  147.  
  148.     /*
  149.      * Reset current draw position
  150.      */
  151.     WaitQueue(4);
  152.     outpw(CUR_X,0x0000);
  153.     outpw(CUR_Y,0x0000);
  154.     /*
  155.      * Reset current colors, foreground is all on, background is 0.
  156.      */
  157.     outpw(FRGD_COLOR,0xFFFF);
  158.     outpw(BKGD_COLOR,0x0000);
  159. }
  160.  
  161. /*
  162.  * setup_8514A_256_color_mode()
  163.  * ============================
  164.  *  Initializes the 8514/A into the requested resolution. Valid input
  165.  *  values are 0 for 640x480 and 1 for 1024x768.
  166.  *
  167.  *  No error checking on input value is performed. If an 8514/A is not
  168.  *  found, or if the 1024 mode is selected, but an appropriate monitor
  169.  *  is not available, this routine will print a message and exit to DOS.
  170.  */
  171.  
  172. #define  MODE_640    0
  173. #define  MODE_1024   1
  174.  
  175. int initRegs[] = {
  176.     DISP_CNTL, ADVFUNC_CNTL, V_TOTAL, V_SYNC_STRT,
  177.     V_DISP, H_TOTAL, H_SYNC_STRT, H_DISP,
  178.     H_SYNC_WID, V_SYNC_WID, DISP_CNTL, 0
  179. };
  180.  
  181. int mode640x8[] = {
  182.     0x0043, 0x0003, 0x0418, 0x03D2,
  183.     0x03BB, 0x0063, 0x0052, 0x004F,
  184.     0x002C, 0x0022, 0x0023
  185. };
  186.  
  187. int mode1024x8[] = {
  188.     0x0053, 0x0007, 0x0660, 0x0600,
  189.     0x05FB, 0x009D, 0x0081, 0x007F,
  190.     0x0016, 0x0008, 0x0033
  191. };
  192.  
  193. void setup_8514A_256_color_mode(int res)
  194. {
  195.     int ii;
  196.  
  197.     /*
  198.      * Blank the screen temporarily to display color 0 by turning
  199.      * the display of all planes off.
  200.      */
  201.     outp(DAC_MASK,0x00);
  202.     /*
  203.      * Reset the 8514/A, and disable all interrupts.
  204.      */
  205.     outpw(SUBSYS_CNTL,GPCTRL_RESET | CHPTEST_NORMAL);
  206.     outpw(SUBSYS_CNTL,GPCTRL_ENAB | CHPTEST_NORMAL);
  207.     outpw(MULTIFUNC_CNTL,MEM_CNTL | VRTCFG_4 | HORCFG_8);
  208.     /*
  209.      * Now initialize the display controller part of the 8514/A.
  210.      * We have set up the initialization values in two sets of
  211.      * tables: 4 bpp and 8 bpp. The "numPlanes" comparison below
  212.      * determines which set of values to use (dual indices).
  213.      */
  214.     for(ii = 0; initRegs[ii] != 0; ii++) {
  215.         int regno = initRegs[ii];
  216.         outpw(regno,(res == MODE_1024) ? mode1024x8[ii] : mode640x8[ii]);
  217.     }
  218.     /*
  219.      * Now reenable the screen, but only the planes that actually exist.
  220.      * Otherwise, you end up with bus noise on the display.
  221.      */
  222.     InitLUT();
  223.     InitEnvironment();
  224.     outpw(DAC_MASK,0xFF);        /* Enable all 8 planes for display */
  225.     status_8514A = 1;
  226. }
  227.  
  228.